import { TOKEN } from '@/common/constant'

let _instance

class LoginServie {
    static instance
    
    constructor(){
		
	}
	
	static getInstance() {
		_instance = _instance || new this()
		return _instance
	}
	
/**
 * 
 */
     isLogin = () => {
         const token = uni.getStorageSync('token')
         if (token) {
             return true
         }
         return false
    }

/**
 * @param { currentPath } 当前页路径，通过路由传参，登录后跳回该页面 
 * @param { currentState } 当前页状态，通过路由传参，登录后跳回该页面是恢复状态
 */
     toLogin = ( currentPath = '', currentState ) => {
         if (this.isLogin()) {
            console.warning('你已登录!')
            return 
         }
		 let _currentPath = currentPath
		 if(!_currentPath){
			 const routePages = getCurrentPages()
			 console.log(routePages)
			 const { route } = routePages[routePages.length-1] || {}
			 _currentPath = route
		 }
	
         uni.$u.route({
			 type: 'redirectTo',
             url: '/pagesB/login/login',
             params : {
				 currentPage : `/${_currentPath}`,
				 ...currentState
			 }
         })
    }
}

export default LoginServie.getInstance()